package com.zhl.mapreduce.wordcount;


import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/*
    keyin , reduce阶段输入的key类型 : Text
    valuein, reduce阶段输入的value类型 : IntWritable
    keyout, reduce阶段输出的key类型 : Text
    valueout, reduce阶段输出的value类型 : IntWritable
*/
public class WordCountReducer extends Reducer<Text, IntWritable,Text, IntWritable> {

    private IntWritable outV = new IntWritable();

    public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {

        int sum = 0;
        //atguigu,(1,1)
        //累加
        for (IntWritable val : values) {
            sum += val.get();
        }
        outV.set(sum);

        //写出
        context.write(key, outV);

    }

}
